package zb.stream;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * @author wzby
 * @Date: 2022/8/5 14:06
 */
public class Stream1 {
    //流技术Stream
    public static void main(String[] args) {
        //用集合创建流
        List<String> ls = new ArrayList<>(Arrays.asList("a", "b", "c"));
        //创建一个顺序流（串行流）
        Stream<String> s1 = ls.stream();
        s1.forEach(System.out::println);
        System.out.println("-=-".repeat(15));

        //数组创建流
        int[] a = {1, 3, 5, 7, 9};
        IntStream s2 = Arrays.stream(a);
        s2.forEach(System.out::println);
        System.out.println("-=-".repeat(15));

        //io建立Stream
        try {
            BufferedReader buf = new BufferedReader(new FileReader("E:\\idea\\java\\ch09\\src\\f\\b.txt"));
            //while (buf.ready()) {
                //System.out.println(buf.readLine());
            //}
            Stream<String> s3 = buf.lines();
            System.out.println(s3.count());
            //s3.forEach(System.out::println);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("-=-".repeat(15));

        //正则表达式生成流
        Pattern p = Pattern.compile("[+]");
        String str = "1+2+3-5-6+9".replace("-","+");
        p.splitAsStream(str).forEach(System.out::println);
    }
}
